//
//  MerChantInfoViewController.m
//  gpos_app
//
//  Created by 崔航飞 on 2018/8/19.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "MerChantInfoViewController.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "MerChantModel.h"
#import "TTCollectionView.h"

//#import "JZLCycleView.h"
@interface MerChantInfoViewController ()<TTCollectionViewDelegate>
@property (nonatomic,strong) UIView *backgroundViews;
@property (nonatomic,strong) UIView *topImage;
@property (nonatomic,strong) UIView *view1;
@property (nonatomic,strong) UIView *view2;
@property (nonatomic,strong) UIView *view3;
@property (nonatomic,strong) UIView *view4;
@property (nonatomic,strong) UILabel *nameLB;
@property (nonatomic,strong) UILabel *ageLB;
@property (nonatomic,strong) UILabel *addressLab;
@property (nonatomic,strong) UILabel *phoneLab;
@property (nonatomic,strong) UILabel *HDLab;

@end

@implementation MerChantInfoViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new]forBarMetrics:UIBarMetricsDefault];
    
    //去掉导航栏底部的黑线
    
    self.navigationController.navigationBar.shadowImage = [UIImage new];
//    self.navigationController.navigationBar.hidden=NO;
    //去掉返回的文字
    self.navigationController.navigationBar.topItem.title = @"";
    self.navigationItem.title=@"";
    self.navigationController.navigationBar.backgroundColor=[UIColor clearColor];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    

}

- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    
 [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    
    [self.navigationController.navigationBar setShadowImage:nil];
   
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
}

-(void)viewDidLayoutSubviews{
    
    [super viewDidLayoutSubviews];
    self.tabBarController.tabBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    self.navigationController.navigationBar.backgroundColor=[UIColor whiteColor];
    self.navigationController.navigationBar.tintColor=[UIColor blackColor];
    [self initUI];
}
-(void)initUI{
    
    self.backgroundViews=[[UIView alloc] init];
    self.backgroundViews.backgroundColor=[UIColor colorWithWhite:0.94 alpha:1];
    self.backgroundViews.frame=CGRectMake(0, 0, self.view.frame.size.width, KmainScreenHeiht  - kBottomSafeHeight);
    [self.view addSubview:self.backgroundViews];

    
    self.topImage=[[UIView alloc] init];
    NSMutableArray *arr=[[NSMutableArray alloc] init];
    if (self.numm==0)
    {
        
        
        for (NSDictionary *dics in self.pictArr)
        {
            
            [arr addObject:[dics objectForKey:@"uri"]];
            
            
        }
    }else{
        
        arr=self.pictArr;
    }
    
    [self.backgroundViews addSubview:self.topImage];
   
    [self.topImage mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.backgroundViews.mas_top);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(240));
        
    }];
    
    //轮播图(可以加载网络图片)

    TTCollectionView *collection = [[TTCollectionView alloc] initWithFrame:CGRectMake(0, 0, self.backgroundViews.frame.size.width, 240)];
    // 这里是设置轮播图的播放间隔
    collection.timeInterval = 2.0;
    // 这里直接传图片的URL字符串(切记是字符串), 要不你还要改里面的图片赋值语句
    collection.imagesArr =arr;
     [self.backgroundViews addSubview:collection];
    // 此属性一定要在collectionView添加到俯视图之后再设置, 这里是设置的轮播图数量
    collection.imagesCount = arr.count;
    // 设置代理(用来解决图片的点击事件)
    collection.collectionViewDelegate = self;
   
    
    self.view1=[[UIView alloc] init];
    self.view1.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.view1];
    [self.view1 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.topImage.mas_bottom).offset(12);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(52));
        
    }];
    
    self.view2=[[UIView alloc] init];
    self.view2.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.view2];
    [self.view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view1.mas_bottom).offset(10);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(52));
        
    }];
    
    self.view3=[[UIView alloc] init];
    self.view3.backgroundColor=[UIColor whiteColor];
    [self.backgroundViews addSubview:self.view3];
    [self.view3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view2.mas_bottom).offset(10);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.height.equalTo(@(52));
        
    }];
    
   
   //设置后面一个lab紧跟前一个
    self.nameLB = [[UILabel alloc]init];
    
    self.nameLB.numberOfLines =0;
    
    [self.view1 addSubview:self.nameLB];

    self.ageLB = [[UILabel alloc]init];
    
    self.ageLB.numberOfLines =0;
    self.ageLB.textColor=[UIColor whiteColor];
    self.ageLB.layer.backgroundColor = [UIColor blueColor].CGColor;
    
    [self.view1 addSubview:self.ageLB];
    NSString* str1;
    if ([self.nameStr isMemberOfClass:[NSNull class]]) {
     str1 =@"";

    }else{
        
       str1 =[NSString stringWithFormat:@"%@",self.nameStr];

    }
    NSString* str21;
    if ([self.typeStr isMemberOfClass:[NSNull class]]) {
        str21=@"";
    }else{
    if (self.numm==0) {
        
     str21 =[NSString stringWithFormat:@"%@",self.typeStr];
    }else if (self.numm==1){
        
        
        if ([self.typeStr isEqualToString:@"2"])
        {
            str21=@"美食";
        }else if ([self.typeStr isEqualToString:@"3"]){
            
            str21=@"娱乐";
            
        }else if ([self.typeStr isEqualToString:@"4"]){
            
            str21=@"购物";
            
        }else if ([self.typeStr isEqualToString:@"5"]){
            
            str21=@"旅游";
        }else if ([self.typeStr isEqualToString:@"6"]){
            
            str21=@"酒店";
        }
        
    }
    }
    UIFont *font = [UIFont fontWithName:@"Arial"size:17];
    
    //设置一个行高上限
    
    CGSize size =CGSizeMake(375,2000);
    
    //计算实际frame大小，并将label的frame变成实际大小
    
    CGSize labelsize = [str1 sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
    
    self.nameLB.font = font;
    
    self.nameLB.text = str1;
    
    [self.nameLB setFrame:CGRectMake(15,15, labelsize.width, labelsize.height)];
    
    
    CGSize labelsize2 = [str21 sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
    
    self.ageLB.font = [UIFont systemFontOfSize:15];
    self.ageLB.textAlignment=NSTextAlignmentCenter;
    self.ageLB.layer.cornerRadius=3;
    self.ageLB.text = str21;
    
    CGFloat x1 =CGRectGetMaxX(self.nameLB.frame);
    
    [self.ageLB setFrame:CGRectMake(x1+10,15, labelsize2.width, labelsize2.height)];
    
    
    UIImageView *img1=[[UIImageView alloc] init];
    img1.image=[UIImage imageNamed:@"icon_dizhi_xq"];
    [self.view2 addSubview:img1];
    [img1 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.view2.mas_left).offset(15);
        make.top.equalTo(self.view2.mas_top).offset(20);
        make.width.equalTo(@(15));
        make.height.equalTo(@(15));
    }];
    
    self.addressLab=[[UILabel alloc] init];
    self.addressLab.font=[UIFont systemFontOfSize:14];
    if ([self.addStr isMemberOfClass:[NSNull class]]) {
        self.addressLab.text=@"";

    }else{
        
        self.addressLab.text=[NSString stringWithFormat:@"%@",self.addStr];

    }
    self.addressLab.numberOfLines=2;
    [self.view2 addSubview:self.addressLab];
    [self.addressLab mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.view2.mas_top).offset(10);
        make.left.equalTo(img1.mas_right).offset(6);
        make.right.equalTo(self.view2.mas_right).offset(-6);
        make.bottom.equalTo(self.view2.mas_bottom).offset(-5);
        
    }];
    
    UIImageView *img2=[[UIImageView alloc] init];
    img2.image=[UIImage imageNamed:@"icon_dianhua_xq"];
    [self.view3 addSubview:img2];
    [img2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.view3.mas_left).offset(15);
        make.top.equalTo(self.view3.mas_top).offset(20);
        make.width.equalTo(@(15));
        make.height.equalTo(@(15));
    }];
    
    self.phoneLab=[[UILabel alloc] init];
    self.phoneLab.font=[UIFont systemFontOfSize:14];
    self.phoneLab.text=[NSString stringWithFormat:@"%@",self.phoneStr];
    [self.view3 addSubview:self.phoneLab];
    [self.phoneLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view3.mas_top).offset(17);
        make.left.equalTo(img2.mas_right).offset(6);
        make.right.equalTo(self.view3.mas_right).offset(-6);
        make.bottom.equalTo(self.view3.mas_bottom).offset(-15);
        
    }];
    
   
    if (self.numm==0)
    {
        self.view4=[[UIView alloc] init];
        self.view4.backgroundColor=[UIColor whiteColor];
        [self.backgroundViews addSubview:self.view4];
        [self.view4 mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.view3.mas_bottom).offset(10);
            make.left.equalTo(self.backgroundViews.mas_left);
            make.right.equalTo(self.backgroundViews.mas_right);
            make.height.equalTo(@(52));
            
        }];
        
        
        UIImageView *img4=[[UIImageView alloc] init];
        img4.image=[UIImage imageNamed:@"icon_huodong_xq"];
        [self.view4 addSubview:img4];
        [img4 mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.view4.mas_left).offset(15);
            make.top.equalTo(self.view4.mas_top).offset(20);
            make.width.equalTo(@(15));
            make.height.equalTo(@(15));
        }];
        
        self.HDLab=[[UILabel alloc] init];
        self.HDLab.font=[UIFont systemFontOfSize:14];
        if ([self.descriptios isMemberOfClass:[NSNull class]]) {
            self.HDLab.text=@"";

        }else{
            
            
            self.HDLab.text=[NSString stringWithFormat:@"%@",self.descriptios];

        }
        self.HDLab.textColor=[UIColor blueColor];
        [self.view4 addSubview:self.HDLab];
        [self.HDLab mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.view4.mas_top).offset(10);
            make.left.equalTo(img4.mas_right).offset(6);
            make.right.equalTo(self.view4.mas_right).offset(-6);
            make.bottom.equalTo(self.view4.mas_bottom).offset(-5);
            
        }];
    }
    
}
#pragma mark - 这里实现cell的点击事件(根据index(也就是indexPath.item))
- (void)cellClickWithIndex:(NSInteger)index {
    
    NSLog(@"点击了第%ld张图片", index);
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
